package com.haydn.practice.restfulweb.dao;

import com.haydn.practice.restfulweb.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

/**
 * @Author haydn
 * @create 2020/9/3 8:18
 *
 * 为springSecurity新创建的dao层类
 */
public class LoginDao {

    private final JdbcTemplate jdbcTemplate;

    //TODO:这里的Autowired还能这么用？
    @Autowired
    public LoginDao(JdbcTemplate jdbcTemplate){
        this.jdbcTemplate = jdbcTemplate;
    }

    public List<User> getUserByUsername(String name){
        String sql = "select id,name,password from user where username = ?";
        return jdbcTemplate.query(sql,new String[]{"username"},new BeanPropertyRowMapper<>(User.class));
    }



}
